//============================================================================
//
// Copyright (c) 2006-2008 Luciano Broussal. All Rights Reserved.
//
// This software is the proprietary information of Luciano Broussal
// Use is subject to license terms.
//
//============================================================================

package org.lbroussal.client.controller;

import com.google.gwt.core.client.GWT;
import org.lbroussal.client.ApplicationFacade;
import org.puremvc4gwt.client.core.controller.CommandProvider;
import org.puremvc4gwt.client.interfaces.ICommand;
import org.puremvc4gwt.client.patterns.command.MacroCommand;

import java.util.ArrayList;
import java.util.List;

public class MyCommandProvider implements CommandProvider {

    public ICommand getCommand(String command) {
        if(command.equals(ApplicationFacade.STARTUP))
            return new StartupCommand();
        if(command.equals(ApplicationFacade.PROCESS_LOGIN))
            return new ProcessLogin();
        if(command.equals(ApplicationFacade.PROCESS_LOGOUT))
            return new ProcessLogout();
        return null;
    }

    public List<ICommand> getSubCommandList(Class<? extends MacroCommand> commandClass) {
        List<ICommand> subCommands = new ArrayList<ICommand>();
        if(GWT.getTypeName(commandClass.getClass()).equals(GWT.getTypeName(StartupCommand.class.getClass()))) {
            subCommands.add(new PrepViewCommand());
            subCommands.add(new PrepModelCommand());
        }else {
            throw new RuntimeException("Unknow type command " + commandClass);
        }
        return subCommands; 
    }
    

}
